# coding:utf-8

from django import template
from urllib import urlencode
register = template.Library()

template_string = '''/lang_switch/?code={{ lang_code }}&next={{ next_url }}'''

@register.tag
def language_url(parser, token):
    try:
        _, code = token.split_contents()
    except (IndexError, AssertionError, ValueError):
        raise template.TemplateSyntaxError
    return LanguageUrl(code)

class LanguageUrl(template.Node):
    def __init__(self, code):
        self.code = code
    def render(self, context):
        next_url = context.get('request').path
        return  "/lang_switch/?code=%s&next=%s" % (self.code, next_url)




